<?php
/**
 * @Notes:【】
 * @Date: 2022-06-03 1:19
 */

namespace Yj\Generator\Core\Common\Template;

use Hyperf\Utils\Str;
use Yj\Generator\Core\Common\RenderableTemplate;
use Yj\Generator\Core\Model\ClassNameModel;

class ClassNameTemplate extends RenderableTemplate
{
    public function toLines()
    {
        $name = '';
        $name .= 'class ' . $this->name;
        if ($this->extends !== null) {
            $name .= sprintf(' extends %s', $this->extends);
        }
        $lines[] = $name;
        $lines[] = '{';
        return $lines;
    }


    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $extends;

    /**
     * PHPClassName constructor.
     * @param string $name
     * @param string|null $extends
     */
    public function __construct($name, $extends = null)
    {
        $this->setName($name)
            ->setExtends($extends);
    }

    /**
     * @param string $name
     *
     * @return $this
     */
    public function setName($name)
    {

        $this->name = Str::studly($name);

        return $this;
    }

    public function getName()
    {
        return $this->name;
    }

    /**
     * @param string $extends
     *
     * @return $this
     */
    public function setExtends($extends)
    {
        $this->extends = $extends;

        return $this;
    }
}